example.js ➔ example   A
last analyzed

Complexity

Conditions 1
Paths 4

Size

Total Lines 73
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 11
c 2
b 0
f 0
nc 4
nop 0
dl 0
loc 73
rs 9.85

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
'use strict';
2
const VBApi = require('./nodeVBulletinAPI');
3
4
example();
5
6
async function example() {
7
    try {
8
        // Let's connect to the server and start our session
9
        let session = new VBApi(
10
            'http://google.com/forum/api.php',
11
            'xXxXxXxX',
12
            'testing script',
13
            '1'
14
        );
15
16
        // To use more command, let's log our session in
17
        // login() uses cleartext while loginMD5() uses md5 hashed password
18
        let userData = await session.login('username', 'password');
19
        console.info('logged in:', userData);
20
21
        // We're now also logged in (login() would have rejected otherwise) , we should be able to do much more
22
        // Here are some more additional actions we can take:
23
24
        // Get the Inbox/private Message list of folder 0
25
        //console.info('got inbox:', await session.getInbox());
26
27
        // Empty the default folder (0) of all messages from 2019.05.18 and prior
28
        //console.info('emptied inbox (returns blank for now):', await session.emptyInbox(new Date('2019.05.18')));
29
30
        // Get the details of Message 241381
31
        //console.info('got message:', await session.getMessage(241381));
32
33
        // Send a Message to user 'Apocsit'
34
        //console.info('sent message (returns blank for now):', await session.sendMessage('Apocist', 'API Test', 'This was sent form the new api library as a test', {signature: true}));
35
36
        // Get a list of Forums and Threads on the homepage
37
        //console.info('got forum list:', await session.getForums());
38
39
        // Get the details of a specific Forum and a list of it's subForums and Threads
40
        //console.info('got forum:', await session.getForum(565));
41
42
        // Get the details of a specific Thread and a list of it's Posts
43
        //console.info('got thread:', await session.getThread(44740));
44
45
        // Attempt to Close a thread, works only if the logged in user has permissions of an inline mod
46
        //console.info('closed thread:', await session.modCloseThread(44740));
47
48
        // Get the details of a specific Member by username
49
        //console.info('got member:', await session.getMember('apocist'));
50
51
52
        /*
53
        console.info(
54
            await session.newPost(
55
                44740,
56
                'Wiggle new testings~!',
57
                {
58
                    signature: true
59
                }
60
            )
61
        );
62
        */
63
64
        /*
65
        console.info(
66
            await session.newThread(
67
                565,
68
                'new Thread test',
69
                'Just testing again!'
70
            )
71
        );
72
        */
73
74
75
    } catch (e) {
76
        console.error(e);
77
    }
78
}